/*
 *    This file is part of SSHTunneler.
 *
 *    Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
 *
 *    SSHTunneler is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    SSHTunneler is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with SSHTunneler.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package sshtunneler.packager.installergenerator;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;

import sshtunneler.library.DefaultPort;
import sshtunneler.library.DefaultPorts;
import sshtunneler.packager.data.TunnelerConfig;

public class ConfigGenerator {
	public ConfigGenerator() {
	}

	public String generate_as_string() {
		StringBuffer s = new StringBuffer();

		s.append("config.ask_username = "
				+ TunnelerConfig.inst.isAsk_username() + "\n");
		s.append("config.overwrite_all = "
				+ TunnelerConfig.inst.isOverwrite_all() + "\n");
		s.append("config.start_minimized = "
				+ TunnelerConfig.inst.isStart_minimized() + "\n");
		s.append("config.connect_on_startup = "
				+ TunnelerConfig.inst.isConnect_to_all_on_start() + "\n");
		s.append("config.hide_tool_config = "
				+ TunnelerConfig.inst.isHide_tool_config() + "\n");
		s.append("config.ports = \\n\\\n");
		s.append("    <PortConfig>\\n\\\n");

		for (DefaultPort p : DefaultPorts.inst.get_all_ports()) {
			s.append("        <PortInfo Port=\"" + p.getPort()
					+ "\" Description=\"" + p.getName() + "\" />\\n\\\n");
		}

		s.append("    </PortConfig>\n");
		s.append("\n");
		s.append("prog.update = " + TunnelerConfig.inst.isProg_update() + "\n");
		s.append("\n");
		s.append("link.debug_link = " + TunnelerConfig.inst.isDebug_link()
				+ "\n");
		s.append("\n");

		return s.toString();
	}

	public void generate_to(File output) throws FileNotFoundException {
		PrintStream out = new PrintStream(output);
		out.println(this.generate_as_string());
		out.close();
	}
}
